<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="keywords"
          th:content="'HTML,Springboot,thymeleaf,markdown,Layui,个人博客,'+${myinfo.getWebname()}+','+${myinfo.getNickname()}"/>
    <title th:text="${myinfo.getWebname()}"></title>
    <link rel="icon" th:href="'/style/images/system/'+${myinfo.getWebicon()}">

    <link rel="stylesheet" href="/dist/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/css/login.css" media="all">
    <script src="/dist/jquery/jquery-3.4.1.min.js"></script>

</head>
<style type="text/css">
    .loginBody {
        background: url(/style/images/system/login_bg.jpg);
        background-size: cover;
    }

</style>
<body class="loginBody">

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login">

    <div class="layadmin-user-login-main">
        <div class="login_face"><img th:src="'/style/images/system/'+${myinfo.getBrandimg()}" class="userAvatar"></div>
        <div class="layadmin-user-login-box layadmin-user-login-header wename">
            <p th:text="${myinfo.getWebname()}"></p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-username"></label>
                <input type="text" name="account" id="LAY-user-login-username" lay-verify="username" placeholder="用户名"
                       maxlength="16" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="password"
                       maxlength="16" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input type="text" maxlength="10" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                               placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="/verifyCode" class="layadmin-user-login-codeimg"
                                 id="LAY-user-get-vercode" onclick="this.src='/verifyCode?'+Math.random()" title="点击刷新验证码">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                <a href="forget" class="layadmin-user-jump-change layadmin-link">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="user-login-submit" id="user_login">登
                    录
                </button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <a href="/register" class="layadmin-user-jump-change layadmin-link">注册帐号</a>
                <a href="/index" class="layadmin-user-jump-change-left layadmin-link">返回首页</a>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">
        <p th:text="${myinfo.getRecord()}"></p>
    </div>
</div>

<script src="/dist/layui/layui.js"></script>
<!--<script src="/script/main.js"></script>-->

<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            username: [
                /^[\S]{6,16}$/
                , '用户名必须是6到16位，且不能出现空格'
            ]
            , password: [
                /^[\S]{6,16}$/
                , '密码必须是6到16位，且不能出现空格'
            ]
        });

        //监听提交
        form.on('submit(user-login-submit)', function (data) {
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/user/userlogin",//url
                data: data.field,
                success: function (result) {
                    if (result.flag == "success") {
                        window.location.href = "/index"
                    } else if (result.flag == "exsit") {
                        layer.msg("您输入的帐号信息不存在！", {icon: 5});
                        document.getElementById("LAY-user-get-vercode").src = "/verifyCode?"+Math.random();
                    }else if (result.flag == "locked") {
                        layer.msg("您的帐号已经被锁定，请联系管理员处理！", {icon: 5});
                        document.getElementById("LAY-user-get-vercode").src = "/verifyCode?"+Math.random();
                    } else if (result.flag == "failed") {
                        layer.msg("用户名或密码错误！", {icon: 2});
                        document.getElementById("LAY-user-get-vercode").src = "/verifyCode?"+Math.random();
                    } else if(result.flag == "failed_vercode"){
                        layer.msg("验证码错误或已过期！");
                        $('#LAY-user-login-vercode').val('');
                        document.getElementById("LAY-user-get-vercode").src = "/verifyCode?"+Math.random();
                    }
                }, error: function () {
                    layer.msg("登录失败，请重试！", {icon: 2});
                }
            });
        });
        $(document).on('keydown', function (event) {
            var event = event || window.event;
            if (event.keyCode == 13) {
                $("#user_login").click();
            }
        });
    });
</script>


</body>
</html>